package bist.believeinstep.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bist.believeinstep.domain.User;
import bist.believeinstep.util.Constant.Role;
import bist.believeinstep.util.Constant.State;

public class UserMapper implements RowMapper<User>{
	public User mapRow(ResultSet rs, int rowNum) throws SQLException{
		User user =  new User();
		user.setId(rs.getInt("id"));
		user.setCode(rs.getString("code"));
		user.setName(rs.getString("name"));
		user.setDob(rs.getDate("dob"));
		user.setIdentifyCode(rs.getString("identify_code"));
		user.setIdentifyDate(rs.getDate("identify_date"));
		user.setIdentifyPlace(rs.getString("identify_place"));
		user.setEmail(rs.getString("email"));
		user.setAddress(rs.getString("address"));
		user.setPhone(rs.getString("phone"));
		user.setCellphone(rs.getString("cellphone"));
		
		String role = rs.getString("role");
		user.setRole(Role.create(role));
		
		String state = rs.getString("state");
		user.setState(State.create(state));
		
		user.setUsername(rs.getString("username"));
		user.setPassword(rs.getString("password"));
		user.setPseudonym(rs.getString("pseudonym"));
		user.setCreated(rs.getTimestamp("created_date"));
		user.setModified(rs.getTimestamp("modified_date"));
		user.setCreatedBy(rs.getString("created_by"));
		user.setModifiedBy(rs.getString("modified_by"));
		
		return user;
	}
}
